package blog.service;

import java.util.Collection;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import blog.dao.ArticleDAO;
import blog.dao.CommentDao;
import blog.domain.Article;
import blog.domain.Comment;
import blog.domain.User;


@Service
@Transactional(propagation=Propagation.REQUIRED)
public class ArticleService 
{
	@Resource
	private ArticleDAO articleDao;
	@Resource
	private CommentDao commentDao;
	
	public void setArticleDao(ArticleDAO contactDao) {
		this.articleDao = contactDao;
	}

	public Collection<Article> getArticles() {
		return articleDao.getArticles();
	}
	
	public Article getArticle(int id) {
		return articleDao.getArticle(id);
	}
	
	public void addArticle(Article article) {
		articleDao.addArticle(article);
	}
	
	public void updateArticle(Article article) {
		articleDao.updateArticle(article);
	}
	
	public void deleteArticle(Article article) {
		articleDao.deleteArticle(article);
	}

	public void editable(User user) {
		articleDao.editable(user);	
	}

	public void unEditable(int id) {
		articleDao.unEditable(id);
	}
	
	public List<Article> getTopTenArticle() {
		return commentDao.getTopTenArticle();
	}

	public List<Comment> getTopTenComment() {
		return commentDao.getTopTenComment();
	}

	public void initEditable() {
		articleDao.initEditable();
	}
}
